/*
 * Copyright 2011 evswork Team
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package org.evswork.getwit.regexp;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.regex.Matcher;

import android.content.Context;

public class RegExpManager {
	public final static int MAX_SIZE = 9;
	
	private static RegExpManager rem;
	
	Context ctxt;
	ArrayList <RegExpObject> data;
	
	private RegExpManager(Context ctxt)
	{
		this.ctxt = ctxt;
		data = new ArrayList <RegExpObject> ();
		int i;
		for (i=0;i<MAX_SIZE;++i)
			data.add(new RegExpObject(ctxt,i));
	}
	
	public ArrayList<RegExpObject> getData() {
		return data;
	}
	
	public boolean match(String input) {
		Iterator<RegExpObject> it;
		RegExpObject o;
		Matcher m;
		for (it=data.iterator();it.hasNext(); )
		{
			o = it.next();
			if (o.status != RegExpObject.ENABLE)
				continue;
			m = o.pattern.matcher(input);
			if (m.find())
				return true;
			
		}
		return false;
	}
	
	public static RegExpManager getInstance(Context ctxt) {
		if (rem == null)
		{
			rem = new RegExpManager(ctxt);
		}
		return rem;
	}
}
